/**
 * Generali Solutions d'assurances - Tous droits réservés &copy; 2007 - 2010
 */
package fr.generali.accueilclient.opt.detaildossier.services.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import fr.generali.accueilclient.commun.exception.AccueilClientBusinessException;
import fr.generali.accueilclient.opt.detaildossier.om.ICriteresRecherchesDetailDossier;
import fr.generali.accueilclient.opt.detaildossier.om.IDossierDetailDossier;
import fr.generali.accueilclient.opt.detaildossier.services.IDetailDossierService;
import fr.generali.relationclient.marketing.opt.detaildossier.services.DossierWSBusinessException;
import fr.generali.relationclient.marketing.opt.detaildossier.services.DossierWSTechnicalException;
import fr.generali.relationclient.marketing.opt.detaildossier.DtoDossier;
import fr.generali.relationclient.marketing.opt.detaildossier.services.IDetailDossierWebService;

/**
 * @author Holmes Kelly
 */

@Service("detailDossierService")
public class DetailDossierService implements IDetailDossierService {

    /**
     * LOGGER
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(DetailDossierService.class);

    /**
     * Appel mapper contenant les assembler
     */
    @Autowired
    @Qualifier("detailDossierMapper")
    private DetailDossierMapper detailDossierMapper;

    /**
     * Appel web service DetailDossierWebService
     */
    @Autowired
    @Qualifier("detailDossierWebService")
    private IDetailDossierWebService detailDossierWebService;

    /**
     * {@inheritDoc}
     */
    public IDossierDetailDossier consulterDetailDossier(ICriteresRecherchesDetailDossier criteresRecherches)
        throws AccueilClientBusinessException {

        IDossierDetailDossier dossier = null;

        if (criteresRecherches != null) {

            try {
                final DtoDossier dtoDossier =
                                detailDossierWebService.consulterDetailDossier(detailDossierMapper
                                                .mapperCriteresRecherches2DtoCriteresRecherches(criteresRecherches));

                if (dtoDossier != null) {

                    dossier = detailDossierMapper.mapperDtoDossier2IDossier(dtoDossier);
                }

            } catch (DossierWSBusinessException e) {

                LOGGER.debug(e.getMessage());

                throw new AccueilClientBusinessException(e.getMessage(), e);

            } catch (DossierWSTechnicalException e) {

                LOGGER.debug(e.getMessage());
            }
        }

        return dossier;
    }

}
